import {createStore,applyMiddleware} from 'redux';

import thunkMiddleware from "redux-thunk"
import {composeWithDevTools} from 'redux-devtools-extension'
import reducer from './reducer.js';

// 状态持久化
import {persistStore, persistReducer} from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';

const persistConfig = {
    key: 'root',
    storage: storage,
    stateReconciler: autoMergeLevel2 // 查看 'Merge Process' 部分的具体情况
};

const myPersistReducer = persistReducer(persistConfig, reducer)

// const compooseEnhancer=window.__REDUX_DEVTOOLS_EXTENSION_COMPOOSE__ || compoose
// 专门用于异步请求的中间件
const storeEnhancer=composeWithDevTools(applyMiddleware(thunkMiddleware))



const  store = createStore(myPersistReducer,storeEnhancer);

export const persistor = persistStore(store)

export default store;

